<?php

namespace Authorization;

use Zend\EventManager\EventInterface;

class Module implements 
    \Zend\ModuleManager\Feature\DependencyIndicatorInterface, 
    \Zend\ModuleManager\Feature\AutoloaderProviderInterface, 
    \Zend\ModuleManager\Feature\ConfigProviderInterface, 
    \Zend\ModuleManager\Feature\BootstrapListenerInterface {

    public function getModuleDependencies() {
        return array('User', 'Authentication');
    }

    public function onBootstrap(EventInterface $e) {
        $app = $e->getTarget();
        $sm = $app->getServiceManager();
        $listener = $sm->get('Authorization\Service\RouteListener');

        $app->getEventManager()->attach($listener);
        
        // bind acl to navigation // TODO: MOVE THIS SOMEWHERE, BUT WHERE?
        $viewHelperManager = $sm->get('ViewHelperManager');
        $navigation = $viewHelperManager->get('navigation');
        $authorizationService = $sm->get('Authorization\Service\AuthorizationService');
        
        $acl = $sm->get('Zend\Permissions\Acl\Acl');
        $navigation->setAcl($acl);
        
        $role = $authorizationService->getRole();
        $navigation->setRole($role);
    }

    public function getAutoloaderConfig() {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__),
            ),
        );
    }

    public function getConfig() {
        return include __DIR__ . '/config/module.config.php';
    }
}